package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.SalesListParam
import com.cheyun.netsalev3.utils.MySharedPreferences
import com.cheyun.netsalev3.utils.api.*
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.json.JSONObject
import kotlin.reflect.KFunction1

class CueTransferActivityRepository(var nkey: String, var ids: String,var level:String) {
    var password = MySharedPreferences.getPassword()
    /**
     * 线索移交
     */
    fun getHandover(disttype:String,salesid: String,owneruid: String, customerlevel: String, remindetime: String, method: () -> Unit) {
        ApiClient.getInstance().getHandover(nkey, ids,
                owneruid,
                customerlevel,
                password,
                remindetime,
                salesid,
                disttype)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<JSONObject>>() {
                    override fun onSuccess(t: BaseResp<JSONObject>) {
                        method()
                    }
                    override fun onError(ex: ApiException) {

                    }
                })
    }

    //获取通道下经销商列表
    fun getSales(kFunction1: KFunction1<@ParameterName(name = "item") List<SalesListParam>, Unit>) {
        ApiClient.getInstance().getChannelsales()
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<SalesListParam>>>() {
                    override fun onSuccess(t: BaseResp<List<SalesListParam>>) {
                        t.data?.apply {
                            kFunction1(this)
                        }
                    }
                    override fun onError(ex: ApiException) {

                    }
                })
    }
}